// This file is part of Visuals, and is based on Winamp's AVS plugin. 
// Copyright 2005 Nullsoft, Inc.
// Copyright 2011 Scott Sibley

var MASK_SH1 = (~(((1<<6)|(1<<15)|(1<<23))<<1));
var MASK_SH2 = (~(((3<<6)|(3<<14)|(3<<22))<<2));
var MASK_SH3 = (~(((7<<5)|(7<<13)|(7<<21))<<3));
var MASK_SH4 = (~(((15<<4)|(15<<12)|(15<<20))<<4));
function DIV_2(x) { return ((( x ) & MASK_SH1)>>1); }
function DIV_4(x) { return ((( x ) & MASK_SH2)>>2); }
function DIV_8(x) { return ((( x ) & MASK_SH3)>>3); }
function DIV_16(x) { return ((( x ) & MASK_SH4)>>4); }

var enabled, roundmode;

function smp_render(this_thread, max_threads, visdata, isBeat, framebuffer, fbout, w, h)
{
	eval(this.getenv());

	if (enabled == 0) return;

	//timingEnter(0);

	var of = new Array();
	var f = new Array();
	for(var i = 0; i < framebuffer.length; i++) {
		var c = Color32_8x4(framebuffer[i]);
		f[i * 4] = c[0];
		f[i * 4 + 1] = c[1];
		f[i * 4 + 2] = c[2];
		f[i * 4 + 3] = c[3];
	}
	var fptr = 0;
	var ofptr = 0;

	if (max_threads < 1) max_threads=1;

	var start_l = ( this_thread * h ) / max_threads;
	var end_l;

	if (this_thread >= max_threads - 1) end_l = h;
	else end_l = ( (this_thread+1) * h ) / max_threads;	

	var outh=end_l-start_l;
	if (outh<1) return;

	var skip_pix=start_l*w;

	fptr += skip_pix;
	ofptr += skip_pix;

	var at_top=0, at_bottom=0;

	if (this_thread == 0) at_top=1;
	if (this_thread >= max_threads - 1) at_bottom=1;
	at_top = 0;
	at_bottom = 0;

	if (enabled == 2) 
	{
		// top line
		if (at_top == 1)
		{	
			var f2 = f;
			var f2ptr=fptr+w;
			var x;
			var adj_tl=0, adj_tl2=0;
			if (roundmode) { adj_tl = 0x03030303; adj_tl2 = 0x04040404; }
			// top left
			of[ofptr++]= DIV_2(f[fptr+0])+DIV_4(f[fptr+0])+DIV_8(f[fptr+1])+DIV_8(f2[f2ptr+0]) + adj_tl; 
			fptr++; f2ptr++;
			// top center
			x=(w-2) / 4;
			while (x--)
			{
				of[ofptr + 0]=DIV_2(f[fptr + 0]) + DIV_8(f[fptr + 0]) + DIV_8(f[fptr + 1]) + DIV_8(f[fptr + -1]) + DIV_8(f2[f2ptr + 0]) + adj_tl2;
				of[ofptr + 1]=DIV_2(f[fptr + 1]) + DIV_8(f[fptr + 1]) + DIV_8(f[fptr + 2]) + DIV_8(f[fptr + 0]) + DIV_8(f2[f2ptr + 1]) + adj_tl2;
				
				of[ofptr + 2]=DIV_2(f[fptr + 2]) + DIV_8(f[fptr + 2]) + DIV_8(f[fptr + 3]) + DIV_8(f[fptr + 1]) + DIV_8(f2[f2ptr + 2]) + adj_tl2;
				of[ofptr + 3]=DIV_2(f[fptr + 3]) + DIV_8(f[fptr + 3]) + DIV_8(f[fptr + 4]) + DIV_8(f[fptr + 2]) + DIV_8(f2[f2ptr + 3]) + adj_tl2;
				fptr+=4;
				f2ptr+=4;
				ofptr+=4;
			}
			x=(w-2)&3;
			while (x--)
			{
				of[ofptr++]=DIV_2(f[fptr+0]) + DIV_8(f[fptr+0]) + DIV_8(f[fptr+1]) + DIV_8(f[fptr+-1]) + DIV_8(f2[f2ptr+0]) + adj_tl2;
				fptr++;
				f2ptr++;
			}
			// top right
			of[ofptr++]=DIV_2(f[fptr + 0])+DIV_4(f[fptr + 0]) + DIV_8(f[fptr + -1])+DIV_8(f2[f2ptr + 0]) + adj_tl; 
			fptr++; f2ptr++;
		}

		// middle block
		{ // Start of new scope.
			var y=outh-at_top-at_bottom;
			var adj_tl1=0,adj_tl2=0;
			var adj2=0;
			if (roundmode) { adj_tl1=0x04040404; adj_tl2=0x05050505; adj2=0x05050505; }
			while (y--)
			{
				var x;
				var f2 = f;
				var f3 = f;
				var f2ptr=fptr+w;
				var f3ptr=fptr-w;
			
				// left edge
				of[ofptr++]=DIV_2(f[fptr+0])+DIV_8(f[fptr+0])+DIV_8(f[fptr+1])+DIV_8(f2[f2ptr+0])+DIV_8(f3[f3ptr+0])+adj_tl1; 
				fptr++; f2ptr++; f3ptr++;

				// middle of line
				x=(w-1);;
				if (roundmode)
				{
					while (x--)
					{
						of[ofptr+0]=DIV_2(f[fptr+0]) + DIV_4(f[fptr+0])+ DIV_16(f[fptr+1])+ DIV_16(f[fptr+-1]) + DIV_16(f2[f2ptr+0]) + DIV_16(f3[f3ptr+0]) + 0x05050505;
						of[ofptr+1]=DIV_2(f[fptr+1]) + DIV_4(f[fptr+1]) + DIV_16(f[fptr+2]) + DIV_16(f[fptr+0]) + DIV_16(f2[f2ptr+1]) + DIV_16(f3[f3ptr+1]) + 0x05050505;
						of[ofptr+2]=DIV_2(f[fptr+2]) + DIV_4(f[fptr+2]) + DIV_16(f[fptr+3]) + DIV_16(f[fptr+1]) + DIV_16(f2[f2ptr+2]) + DIV_16(f3[f3ptr+2]) + 0x05050505;
						of[ofptr+3]=DIV_2(f[fptr+3]) + DIV_4(f[fptr+3]) + DIV_16(f[fptr+4]) + DIV_16(f[fptr+2]) + DIV_16(f2[f2ptr+3]) + DIV_16(f3[f3ptr+3]) + 0x05050505;
						fptr+=4;
						f2ptr+=4;
						f3ptr+=4;
						ofptr+=4;
					}
				}
				else
				{
					while (x--)
					{
						of[ofptr+0]=DIV_2(f[fptr+0]) + DIV_4(f[fptr+0]) + DIV_16(f[fptr+1]) + DIV_16(f[fptr+-1]) + DIV_16(f2[f2ptr+0]) + DIV_16(f3[f3ptr+0]);
						of[ofptr+1]=DIV_2(f[fptr+1]) + DIV_4(f[fptr+1]) + DIV_16(f[fptr+2]) + DIV_16(f[fptr+0]) + DIV_16(f2[f2ptr+1]) + DIV_16(f3[f3ptr+1]);
						of[ofptr+2]=DIV_2(f[fptr+2]) + DIV_4(f[fptr+2]) + DIV_16(f[fptr+3]) + DIV_16(f[fptr+1]) + DIV_16(f2[f2ptr+2]) + DIV_16(f3[f3ptr+2]);
						of[ofptr+3]=DIV_2(f[fptr+3]) + DIV_4(f[fptr+3]) + DIV_16(f[fptr+4]) + DIV_16(f[fptr+2]) + DIV_16(f2[f2ptr+3]) + DIV_16(f3[f3ptr+3]);
						fptr+=4;
						f2ptr+=4;
						f3ptr+=4;
						ofptr+=4;
					}
				}

				x=(w-2)&3;
				while (x--)
				{
					of[ofptr++]=DIV_2(f[fptr+0]); + DIV_4(f[fptr+0]) + DIV_16(f[fptr+1]) + DIV_16(f[fptr+-1]) + DIV_16(f2[f2ptr+0]) + DIV_16(f3[f3ptr+0]) + adj_tl2;
					fptr++;
					f2ptr++;
					f3ptr++;
				}

				// right block
				of[ofptr++]=DIV_2(f[fptr+0])+DIV_8(f[fptr+0])+DIV_8(f[fptr+-1])+DIV_8(f2[fptr+0])+DIV_8(f3[fptr+0])+adj_tl1; 
				fptr++;
			}
		}
		// bottom block
		if (at_bottom == 1)
		{
			 var f2=f;
			var f2ptr=fptr-w;
			var x;
			var adj_tl=0, adj_tl2=0;
			if (roundmode) { adj_tl = 0x03030303; adj_tl2 = 0x04040404; }
			// bottom left
			of[ofptr++]=DIV_2(f[fptr+0])+DIV_4(f[fptr+0])+DIV_8(f[fptr+1])+DIV_8(f2[fptr+0]) + adj_tl; 
			fptr++; f2ptr++;
			// bottom center
			x=(w-2) / 4;
			x = 200;
			while (x--)
			{
				of[ofptr+0]=DIV_2(f[fptr+0]) + DIV_8(f[fptr+0]) + DIV_8(f[fptr+1]) + DIV_8(f[fptr+-1]) + DIV_8(f2[fptr+0]) + adj_tl2;
				of[ofptr+1]=DIV_2(f[fptr+1]) + DIV_8(f[fptr+1]) + DIV_8(f[fptr+2]) + DIV_8(f[fptr+0]) + DIV_8(f2[fptr+1]) + adj_tl2;
				of[ofptr+2]=DIV_2(f[fptr+2]) + DIV_8(f[fptr+2]) + DIV_8(f[fptr+3]) + DIV_8(f[fptr+1]) + DIV_8(f2[fptr+2])+adj_tl2;
				of[ofptr+3]=DIV_2(f[fptr+3]) + DIV_8(f[fptr+3]) + DIV_8(f[fptr+4]) + DIV_8(f[fptr+2]) + DIV_8(f2[fptr+3])+adj_tl2;
				fptr+=4;
				f2ptr+=4;
				ofptr+=4;
			}
			x=(w-2)&3;
			x = 200;
			while (x--)
			{
				of[ofptr++]=DIV_2(f[fptr+0]) + DIV_8(f[fptr+0]) + DIV_8(f[fptr+1]) + DIV_8(f[fptr+-1]) + DIV_8(f2[fptr+0])+adj_tl2;
				f+=2;
				f2+=2;
			}
			// bottom right
			of[ofptr++]=DIV_2(f[fptr+0])+DIV_4(f[fptr+0]) + DIV_8(f[fptr+-1])+DIV_8(f2[f2ptr+0])+adj_tl; fptr++; f2ptr++;
		}
	}
	else if (enabled == 3) // more blur
	{
		// top line
		if (at_top) {
			var f2 = f;
			var f2ptr=fptr+w;
			var x;
			var adj_tl=0, adj_tl2=0;
			if (roundmode) { adj_tl = 0x02020202; adj_tl2 = 0x01010101; }
			// top left
			of[ofptr++]=DIV_2(f[fptr+1])+DIV_2(f2[f2ptr+0]) + adj_tl2; fptr++; f2ptr++;
			// top center
			x=(w-2);
			while (x--)
			{
				of[ofptr+0]=DIV_4(f[fptr+1]) + DIV_4(f[fptr+-1]) + DIV_2(f2[f2ptr+0]) + adj_tl;
				of[ofptr+1]=DIV_4(f[fptr+2]) + DIV_4(f[fptr+0]) + DIV_2(f2[f2ptr+1]) +adj_tl;
				of[ofptr+2]=DIV_4(f[fptr+3]) + DIV_4(f[fptr+1]) + DIV_2(f2[f2ptr+2]) + adj_tl;
				of[ofptr+3]=DIV_4(f[fptr+4]) + DIV_4(f[fptr+2]) + DIV_2(f2[f2ptr+3]) + adj_tl;
				fptr+=4;
				f2ptr+=4;
				ofptr+=4;
			}
			x=(w-2)&3;
			while (x--)
			{
				of[ofptr++]=DIV_4(f[ptr+1]) + DIV_4(f[fptr+-1]) + DIV_2(f2[f2ptr+0])+adj_tl;
				fptr++;
				f2ptr++;
			}
			// top right
			of[ofptr++]=DIV_2(f[fptr+-1])+DIV_2(f2[f2ptr+0])+adj_tl2; fptr++; f2ptr++;
		}


		// middle block
		{
			var y=outh-at_top-at_bottom;
			var adj_tl1=0,adj_tl2=0;
			var adj2=0;
			if (roundmode) { adj_tl1=0x02020202; adj_tl2=0x03030303; } // adj2=0x0303030303030303i64; }

			while (y--)
			{
				var x;
				var f2=f;
				var f2ptr = fptr+w;
				var f3=f;
				var f3ptr = fptr-w;
			
				// left edge
				of[ofptr++]=DIV_2(f[fptr+1])+DIV_4(f2[f2ptr+0])+DIV_4(f3[f3ptr+0]) + adj_tl1; fptr++; f2ptr++; f3ptr++;

				// middle of line
				x=(w-2);
				if (roundmode)
				{
					while (x--)
					{
						of[ofptr+0]=DIV_4(f[fptr+1]) + DIV_4(f[fptr+-1]) + DIV_4(f2[f2ptr+0]) + DIV_4(f3[f3ptr+0]) + 0x03030303;
						of[ofptr+1]=DIV_4(f[fptr+2]) + DIV_4(f[fptr+0]) + DIV_4(f2[f2ptr+1]) + DIV_4(f3[f3ptr+1]) + 0x03030303;
						of[ofptr+2]=DIV_4(f[fptr+3]) + DIV_4(f[fptr+1]) + DIV_4(f2[f2ptr+2]) + DIV_4(f3[f3ptr+2]) + 0x03030303;
						of[ofptr+3]=DIV_4(f[fptr+4]) + DIV_4(f[fptr+2]) + DIV_4(f2[f2ptr+3]) + DIV_4(f3[f3ptr+3]) + 0x03030303;
						fptr+=4; f2ptr+=4; f3ptr+=4; ofptr+=4;
					}
				}
				else
				{
					while (x--)
					{
						of[ofptr+0]=DIV_4(f[fptr+1]) + DIV_4(f[fptr+-1]) + DIV_4(f2[f2ptr+0]) + DIV_4(f3[f3ptr+0]);
						of[ofptr+1]=DIV_4(f[fptr+2]) + DIV_4(f[fptr+0]) + DIV_4(f2[f2ptr+1]) + DIV_4(f3[f3ptr+1]);
						of[ofptr+2]=DIV_4(f[fptr+3]) + DIV_4(f[fptr+1]) + DIV_4(f2[f2ptr+2]) + DIV_4(f3[f3ptr+2]);
						of[ofptr+3]=DIV_4(f[fptr+4]) + DIV_4(f[fptr+2]) + DIV_4(f2[f2ptr+3]) + DIV_4(f3[f3ptr+3]);
						fptr+=4; f2ptr+=4; f3ptr+=4; ofptr+=4;
					}
				}

				x=(w-2)&3;
				while (x--)
				{
					of[ofptr++]=DIV_4(f[fptr+1]) + DIV_4(f[fptr+-1]) + DIV_4(f2[f2ptr+0]) + DIV_4(f3[f3ptr+0]) + adj_tl2;
					fptr+=4;
					f2ptr+=4;
					f3ptr+=4;
				}

				// right block
				of[ofptr++]=DIV_2(f[fptr+-1])+DIV_4(f2[f2ptr+0])+DIV_4(f3[f2ptr+0]) + adj_tl1; fptr++;
			}
		}

		// bottom block
		if (at_bottom == 1)
		{
			var f2=f;
			var f2ptr = fptr-w;
			var x;
			var adj_tl=0, adj_tl2=0;
			if (roundmode) { adj_tl = 0x02020202; adj_tl2 = 0x01010101; }
			// bottom left
			of[ofptr++]=DIV_2(f[fptr+1])+DIV_2(f2[f2ptr+0]) + adj_tl2; fptr++; f2ptr++;
			// bottom center
			x=(w-2);
			while (x--)
			{
				of[ofptr+0]=DIV_4(f[fptr+1]) + DIV_4(f[fptr+-1]) + DIV_2(f2[f2ptr+0])+adj_tl;
				of[ofptr+1]=DIV_4(f[fptr+2]) + DIV_4(f[fptr+0]) + DIV_2(f2[f2ptr+1])+adj_tl;
				of[ofptr+2]=DIV_4(f[fptr+3]) + DIV_4(f[fptr+1]) + DIV_2(f2[f2ptr+2])+adj_tl;
				of[ofptr+3]=DIV_4(f[fptr+4]) + DIV_4(f[fptr+2]) + DIV_2(f2[f2ptr+3])+adj_tl;
				fptr+=4;
				f2ptr+=4;
				ofptr+=4;
			}
			x=(w-2)&3;
			while (x--)
			{
				of[ofptr++]=DIV_4(f[fptr+1]) + DIV_4(f[fptr+-1]) + DIV_2(f2[f2ptr+0])+adj_tl;
				f++;
				f2++;
			}
			// bottom right
			of[ofptr++]=DIV_2(f[fptr+-1])+DIV_2(f2[f2ptr+0])+adj_tl2; fptr++; f2ptr++;
		}
	}
	else
	{
		// top line
		if (at_top == 1) 
		{
			var f2=f;
			var f2ptr = fptr+w;
			var x;
			var adj_tl=0, adj_tl2=0;
			if (roundmode) { adj_tl = 0x02020202; adj_tl2 = 0x03030303; }
			// top left
			of[ofptr++]=DIV_2(f[fptr+0])+DIV_4(f[fptr+1])+DIV_4(f2[f2ptr+0]) + adj_tl; fptr++; f2ptr++;
			// top center
			x=(w-2);
			while (x--)
			{
				of[ofptr+0]=DIV_4(f[fptr+0]) + DIV_4(f[fptr+1]) + DIV_4(f[fptr+-1]) + DIV_4(f2[f2ptr+0]) + adj_tl2;
				of[ofptr+1]=DIV_4(f[fptr+1]) + DIV_4(f[fptr+2]) + DIV_4(f[fptr+0]) + DIV_4(f2[f2ptr+1]) + adj_tl2;
				of[ofptr+2]=DIV_4(f[fptr+2]) + DIV_4(f[fptr+3]) + DIV_4(f[fptr+1]) + DIV_4(f2[f2ptr+2]) + adj_tl2;
				of[ofptr+3]=DIV_4(f[fptr+3]) + DIV_4(f[fptr + 4]) + DIV_4(f[fptr+2]) + DIV_4(f2[f2ptr+3]) + adj_tl2;
				fptr+=4;
				f2ptr+=4;
				ofptr+=4;
			}
			x=(w-2)&3;
			while (x--)
			{
				of[ofptr++]=DIV_4(f[fptr+0]) + DIV_4(f[fptr+1]) + DIV_4(f[fptr+-1]) + DIV_4(f2[f2ptr+0]) + adj_tl2;
				fptr++;
				f2ptr++;
			}
			// top right
			of[ofptr++]=DIV_2(f[fptr+0])+DIV_4(f[fptr+-1])+DIV_4(f2[f2ptr+0]) + adj_tl; 
			fptr++; f2ptr++;
		}

		// middle block
		{
			var y=outh-at_top-at_bottom;
			var adj_tl1=0,adj_tl2=0;
			var adj2=0;
			if (roundmode) { adj_tl1=0x03030303; adj_tl2=0x04040404; }; // adj2=0x0404040404040404i64; }
			while (y--)
			{
				var x;
				var f2 = f;
				var f2ptr = fptr+w;
				var f3 = f;
				var f3ptr = fptr-w;
			
				// left edge
				of[ofptr++]=DIV_4(f[fptr+0])+DIV_4(f[fptr+1])+DIV_4(f2[f2ptr+0])+DIV_4(f3[f3ptr+0])+adj_tl1; fptr++; f2ptr++; f3ptr++;

				// middle of line
				x=(w-2);
				if (roundmode)
				{
					while (x--)
					{
						of[ofptr+0]=DIV_2(f[ofptr+0]) + DIV_8(f[fptr+1]) + DIV_8(f[fptr+-1]) + DIV_8(f2[f2ptr+0]) + DIV_8(f3[f3ptr+0]) + 0x04040404;
						of[ofptr+1]=DIV_2(f[ofptr+1]) + DIV_8(f[fptr+2]) + DIV_8(f[fptr+0]) + DIV_8(f2[f2ptr+1]) + DIV_8(f3[f3ptr+1]) + 0x04040404;
						of[ofptr+2]=DIV_2(f[ofptr+2]) + DIV_8(f[fptr+3]) + DIV_8(f[fptr+1]) + DIV_8(f2[f2ptr+2]) + DIV_8(f3[f3ptr+2]) + 0x04040404;
						of[ofptr+3]=DIV_2(f[ofptr+3]) + DIV_8(f[fptr+4]) + DIV_8(f[fptr+2]) + DIV_8(f2[f2ptr+3]) + DIV_8(f3[f3ptr+3]) + 0x04040404;
						fptr+=4; f2ptr+=4; f3ptr+=4; ofptr+=4;
					}
				}
				else
				{
					while (x--)
					{
						of[ofptr+0]=DIV_2(f[0]) + DIV_8(f[1]) + DIV_8(f[-1]) + DIV_8(f2[0]) + DIV_8(f3[0]);
						of[ofptr+1]=DIV_2(f[1]) + DIV_8(f[2]) + DIV_8(f[0]) + DIV_8(f2[1]) + DIV_8(f3[1]);
						of[ofptr+2]=DIV_2(f[2]) + DIV_8(f[3]) + DIV_8(f[1]) + DIV_8(f2[2]) + DIV_8(f3[2]);
						of[ofptr+3]=DIV_2(f[3]) + DIV_8(f[4]) + DIV_8(f[2]) + DIV_8(f2[3]) + DIV_8(f3[3]);
						fptr+=2; f2ptr+=2; f3ptr+=2; ofptr+=2;
					}
				}

				x=(w-2)&3;
				while (x--)
				{
					of[ofptr++]=DIV_2(f[fptr+0]) + DIV_8(f[fptr+1]) + DIV_8(f[fptr+-1]) + DIV_8(f2[f2ptr+0]) + DIV_8(f3[f3ptr+0]) + adj_tl2;
					fptr++;
					f2ptr++;
					f3ptr++;
				}

				// right block
				of[ofptr++]=DIV_4(f[fptr+0])+DIV_4(f[fptr+-1])+DIV_4(f2[f2ptr+0])+DIV_4(f3[f3ptr+0]) + adj_tl1; fptr++;
			}
		}
		// bottom block
		if (at_bottom == 1)
		{
			var f2=f;
			var f2ptr = fptr-w;
			var adj_tl=0, adj_tl2=0;
			if (roundmode) { adj_tl = 0x02020202; adj_tl2 = 0x03030303; }
			var x;
			// bottom left
			of[ofptr++]=DIV_2(f[fptr+0])+DIV_4(f[fptr+1])+DIV_4(f2[f2ptr+0]) + adj_tl; fptr++; f2ptr++;
			// bottom center
			x=(w-2);
			while (x--)
			{
				of[ofptr+0]=DIV_4(f[fptr+0]) + DIV_4(f[fptr+1]) + DIV_4(f[fptr+-1]) + DIV_4(f2[f2ptr+0]) + adj_tl2;
				of[ofptr+1]=DIV_4(f[fptr+1]) + DIV_4(f[fptr+2]) + DIV_4(f[fptr+0]) + DIV_4(f2[f2ptr+1]) + adj_tl2;
				of[ofptr+2]=DIV_4(f[fptr+2]) + DIV_4(f[fptr+3]) + DIV_4(f[fptr+1]) + DIV_4(f2[f2ptr+2]) + adj_tl2;
				of[ofptr+3]=DIV_4(f[fptr+3]) + DIV_4(f[fptr+4]) + DIV_4(f[fptr+2]) + DIV_4(f2[f2ptr+3]) + adj_tl2;
				fptr+=4;
				f2ptr+=4;
				ofptr+=4;
			}
			x=(w-2)&3;
			while (x--)
			{
				of[ofptr++]=DIV_4(f[fptr+0]) + DIV_4(f[fptr+1]) + DIV_4(f[fptr+-1]) + DIV_4(f2[f2ptr+0]) + adj_tl2;
				fptr++;
				f2ptr++;
			}
			// bottom right
			of[ofptr++]=DIV_2(f[fptr+0])+DIV_4(f[fptr+-1])+DIV_4(f2[f2ptr+0]) + adj_tl; fptr++; f2ptr++;
		}
	}	
	for(var i = 0; i < framebuffer.length; i++) {
		fbout[i] = Color8x4_32(of[i * 4], of[i * 4 + 1], of[i * 4 + 2], of[i * 4 + 3])
	}

	//eval(this.setenv());
	//timingLeave(0);
	return 1;
}

function smp_begin(max_threads, visdata, isBeat, framebuffer, fbout, w, h)
{
	//visdata[2][2][576]
	if (!this.enabled) return 0;
	return max_threads;
}


function smp_finish(visdata, isBeat, framebuffer, fbout, w, h) // return value is that of render() for fbstuff etc
{
	return !!this.enabled;
}

function blur_render(this_thread, max_threads, visdata, isBeat, framebuffer, fbout, w, h)
{
	this.smp_begin(1,visdata,isBeat,framebuffer,fbout,w,h);
	//if (!isBeat) return 0;

	this.smp_render(0,1,visdata,isBeat,framebuffer,fbout,w,h);

	return true;
	//return this.smp_finish(visdata,isBeat,framebuffer,fbout,w,h);
}

var r_blur = function(name, enabled, roundmode) {
	this.name = name;
	this.variables = new Array();
	this.addvar("roundmode", roundmode);
	this.addvar("enabled", enabled);
}

r_blur.prototype.render = blur_render;
r_blur.prototype.smp_begin = smp_begin;
r_blur.prototype.smp_render = smp_render;
r_blur.prototype.smp_finish = smp_finish;

r_blur.prototype.addvar = addvar;
r_blur.prototype.setvar = setvar;
r_blur.prototype.getenv = getenv;
r_blur.prototype.setenv = setenv;

